---
title:        'Linear Advance Calibration Pattern'
description:  'Create G-code to calibrate LIN_ADVANCE setting'
category:     [ tools ]
---
<script language="JavaScript" type="text/javascript" src="{{ site.js }}jquery-2.2.1.min.js"></script>
<script language="JavaScript" type="text/javascript" src="{{ site.js }}jquery-ui.min.js"></script>
<script language="JavaScript" type="text/javascript" src="./FileSaver.min.js"></script>
<script language="JavaScript" type="text/javascript" src="./k-factor.js"></script>
<div class="container" role="main">
  <div class="row">
    <div class="calibpat" id="calibpat">
      <h1>K-factor Calibration Pattern</h1>
      <div class="row alert alert-info custom-alert">
        <div class="col-lg-1 col-md-2 visible-lg-block visible-md-block custom-alert-icon"> <i class="fa fa-info-circle fa-4x" aria-hidden="true"></i> </div>
        <div class="col-lg-11 col-md-10 custom-alert-text">
          <p><em>Caution!</em><br/>
          K-values for Linear Advance 1.0 and 1.5 are not compatible.<br/>
          Linear Advance 1.0 is used in Marlin 1.1.8 and earlier.<br/>
          Linear Advance 1.5 is used in Marlin 1.1.9 and later.</p>
        </div>
      </div>
      <p>Use this form to generate G-code that you can use to calibrate your Linear Advance K-factor. Default values apply to standard PLA with a 0.4mm nozzle.</p>
      <p>Press the <code class="highlighter-rouge">Generate G-code</code> button followed by <code class="highlighter-rouge">Download as file</code> to save the result.</p>
      <table id="kfactor">
        <tbody>
          <tr>
            <td colspan="3" class="tdHead"><h3>Settings</h3></td>
            <td class="tdHead"><h3>G-code</h3></td>
          </tr>
          <tr>
            <td colspan="3" class="tdSection"><h4>Printer:</h4></td>
            <td rowspan="47" class="txtareatd"><textarea name="textarea" id="textarea"></textarea></td>
          </tr>
          <tr>
            <td><label for="PRINTER">Printer:</label></td>
            <td><input name="PRINTER" id="PRINTER" value="printer name" /></td>
          </tr>
          <tr>
            <td><label for="FILAMENT">Filament:</label></td>
            <td><input name="FILAMENT" id="FILAMENT" value="filament name" /></td>
          </tr>
          <tr>
            <td><label for="FIL_DIA">Filament Diameter:</label></td>
            <td><input name="FIL_DIA" id="FIL_DIA" step="any" value="1.75" onblur="validateInput()" /></td>
            <td>Diameter of the used filament (mm)</td>
          </tr>
          <tr>
            <td><label for="NOZ_DIA">Nozzle Diameter:</label></td>
            <td><input name="NOZ_DIA" id="NOZ_DIA" step="any" value="0.4" onblur="validateInput()" /></td>
            <td>Diameter of the nozzle (mm)</td>
          </tr>
          <tr>
            <td><label for="NOZZLE_TEMP">Nozzle Temperature:</label></td>
            <td><input name="NOZZLE_TEMP" id="NOZZLE_TEMP" step="any" value="205" onblur="validateInput()" /></td>
            <td>Nozzle Temperature (°C)</td>
          </tr>
          <tr>
            <td><label for="BED_TEMP">Bed Temperature:</label></td>
            <td><input name="BED_TEMP" id="BED_TEMP" step="any" value="60" onblur="validateInput()" /></td>
            <td>Bed Temperature (°C)</td>
          </tr>
          <tr>
            <td><label for="RETRACTION">Retraction Distance:</label></td>
            <td><input name="RETRACTION" id="RETRACTION" step="any" value="1" onblur="validateInput()" /></td>
            <td>Retraction distance (mm)</td>
          </tr>
          <tr>
            <td><label for="LAYER_HEIGHT">Layer Height:</label></td>
            <td><input name="LAYER_HEIGHT" id="LAYER_HEIGHT" step="0.1" value="0.2" onblur="validateInput()" /></td>
            <td>Layer Height (mm)</td>
          </tr>
          <tr>
            <td><label for="TOOL_INDEX">Extruder:</label></td>
            <td><input name="TOOL_INDEX" id="TOOL_INDEX" step="1" value="0" onblur="validateInput()" /></td>
            <td>Extruder Index (0 to ?)</td>
          </tr>
          <tr>
            <td><label for="FAN_SPEED">Fan Speed:</label></td>
            <td><input name="FAN_SPEED" id="FAN_SPEED" step="1" value="0" onblur="validateInput()" /></td>
            <td>Fan Speed (%)</td>
          </tr>
          <tr>
            <td colspan="3" class="tdSection"><h4>Print Bed:</h4></td>
          </tr>
          <tr>
            <td><label for="SHAPE_BED">Bed Shape:</label></td>
            <td><select name="SHAPE_BED" id="SHAPE_BED">
              <option value="Rect">Rectangular</option>
              <option value="Round">Round</option>
            </select></td>
            <td>Rectangular or round bed. Round beds will activate Origin Bed Center</td>
          </tr>
          <tr>
            <td><label for="BEDSIZE_X">Bed Size X:</label></td>
            <td><input name="BEDSIZE_X" id="BEDSIZE_X" step="any" value="200" onblur="validateInput()" /></td>
            <td id="shape">Size (mm) of the bed in X</td>
          </tr>
          <tr>
            <td><label for="BEDSIZE_Y">Bed Size Y:</label></td>
            <td><input name="BEDSIZE_Y" id="BEDSIZE_Y" step="any" value="200" onblur="validateInput()" /></td>
            <td>Size (mm) of the bed in Y</td>
          </tr>
          <tr>
            <td><label for="CENTER_NULL">Origin Bed Center:</label></td>
            <td><input name="CENTER_NULL" type="checkbox" id="CENTER_NULL" /></td>
            <td>Set the origin position (X0 Y0) to bed center instead of front-left corner</td>
          </tr>
          <tr>
            <td colspan="3" class="tdSection"><h4>Speed:</h4></td>
          </tr>
          <tr>
            <td><label for="MM_S">Use mm/s:</label></td>
            <td><input name="MM_S" type="checkbox" id="MM_S" checked="checked" /></td>
            <td>Use mm/s instead of mm/m</td>
          </tr>
          <tr>
            <td><label for="SLOW_SPEED">Slow Printing Speed:</label></td>
            <td><input name="SLOW_SPEED" id="SLOW_SPEED" step="any" value="20" onblur="validateInput()" /></td>
            <td>Slow printing speed</td>
          </tr>
          <tr>
            <td><label for="FAST_SPEED">Fast Printing Speed:</label></td>
            <td><input name="FAST_SPEED" id="FAST_SPEED" step="any" value="70" onblur="validateInput()" /></td>
            <td>Fast printing speed. This should differ noticeably from Slow Speed</td>
          </tr>
          <tr>
            <td><label for="MOVE_SPEED">Movement Speed:</label></td>
            <td><input name="MOVE_SPEED" id="MOVE_SPEED" step="any" value="120" onblur="validateInput()" /></td>
            <td>Movement speed</td>
          </tr>
          <tr>
            <td><label for="RETRACT_SPEED">Retract Speed:</label></td>
            <td><input name="RETRACT_SPEED" id="RETRACT_SPEED" step="any" value="30" onblur="validateInput()" /></td>
            <td>Retract Speed of the extruder</td>
          </tr>
          <tr>
            <td><label for="UNRETRACT_SPEED">Unretract Speed:</label></td>
            <td><input name="UNRETRACT_SPEED" id="UNRETRACT_SPEED" step="any" value="30" onblur="validateInput()" /></td>
            <td>Unretract Speed of the extruder</td>
          </tr>
          <tr>
            <td><label for="PRINT_ACCL">Acceleration:</label></td>
            <td><input name="PRINT_ACCL" id="PRINT_ACCL" step="any" value="500" onblur="validateInput()" /></td>
            <td>Set printing acceleration (mm/s^2)</td>
          </tr>
          <tr>
            <td><label for="X_JERK">Jerk X:</label></td>
            <td><input name="X_JERK" id="X_JERK" step="1" value="-1" onblur="validateInput()" /></td>
            <td>Set the Jerk for the X-axis. -1 to use firmware default</td>
          </tr>
          <tr>
            <td><label for="Y_JERK">Jerk Y:</label></td>
            <td><input name="Y_JERK" id="Y_JERK" step="1" value="-1" onblur="validateInput()" /></td>
            <td>Set the Jerk for the Y-axis. -1 to use firmware default</td>
          </tr>
          <tr>
            <td><label for="Z_JERK">Jerk Z:</label></td>
            <td><input name="Z_JERK" id="Z_JERK" step="1" value="-1" onblur="validateInput()" /></td>
            <td>Set the Jerk for the Z-axis. -1 to use firmware default</td>
          </tr>
          <tr>
            <td><label for="E_JERK">Jerk E:</label></td>
            <td><input name="E_JERK" id="E_JERK" step="1" value="-1" onblur="validateInput()" /></td>
            <td>Set the Jerk for the Extruder. -1 to use firmware default</td>
          </tr>
          <tr>
            <td colspan="3" class="tdSection"><h4>Pattern:</h4></td>
          </tr>
          <tr>
            <td><label for="LIN_VERSION">Lin Advance Version:</label></td>
            <td><select name="LIN_VERSION" id="LIN_VERSION">
              <option value="1.0">1.0</option>
              <option value="1.5" selected="selected">1.5</option>
            </select></td>
            <td>Select version 1.0 for Marlin 1.1.8 and earlier. Select 1.5 for Marlin 1.1.9 / 2.0 and up</td>
          </tr>
          <tr>
            <td><label for="TYPE_PATTERN">Pattern Type:</label></td>
            <td><select name="TYPE_PATTERN" id="TYPE_PATTERN">
              <option value="std">Standard</option>
              <option value="alt">Alternate</option>
            </select></td>
            <td>Select standard or alternate pattern</td>
          </tr>
          <tr>
            <td><label for="K_START">Starting Value for K:</label></td>
            <td><input name="K_START" id="K_START" step="any" value="0" onblur="validateInput()" /></td>
            <td id="start_factor">Starting value for the K-factor</td>
          </tr>
          <tr>
            <td><label for="K_END">Ending Value for K:</label></td>
            <td><input name="K_END" id="K_END" step="any" value="2" onblur="validateInput()" /></td>
            <td id="end_factor">Ending value of the K-factor</td>
          </tr>
          <tr>
            <td><label for="K_STEP">K-factor Stepping:</label></td>
            <td><input name="K_STEP" id="K_STEP" step="any" value="0.2" onblur="validateInput()" /></td>
            <td id="step_factor">Stepping of the K-factor in the test pattern. Needs to be an exact divisor of the K-factor Range (End - Start)</td>
          </tr>
          <tr>
            <td><label for="SLOW_LENGTH">Slow Speed Length:</label></td>
            <td><input name="SLOW_LENGTH" id="SLOW_LENGTH" step="1" value="20" onblur="validateInput()" /></td>
            <td>Length of the Slow Speed test-line (mm)</td>
          </tr>
          <tr>
            <td><label for="FAST_LENGTH">Fast Speed Length:</label></td>
            <td><input name="FAST_LENGTH" id="FAST_LENGTH" step="1" value="40" onblur="validateInput()" /></td>
            <td>Length of the Fast Speed test-line (mm)</td>
          </tr>
          <tr>
            <td><label for="SPACE_LINE">Test Line Spacing:</label></td>
            <td><input name="SPACE_LINE" id="SPACE_LINE" step="0.1" value="5" onblur="validateInput()" /></td>
            <td>Distance between the test lines. This will impact print size</td>
          </tr>
          <tr>
            <td><label for="FRAME">Print Anchor Frame:</label></td>
            <td><input name="FRAME" type="checkbox" id="FRAME" /></td>
            <td>Adds a frame around the start and end points of the test lines. May improve adhesion</td>
          </tr>
          <tr>
            <td><label for="DIR_PRINT">Printing Direction:</label></td>
            <td><select name="DIR_PRINT" id="DIR_PRINT" onchange="validateInput()">
              <option value="0" selected="selected">Left to Right (0°)</option>
              <option value="45">45°</option>
              <option value="90">Front to Back (90°)</option>
              <option value="135">135°</option>
              <option value="180">Right to Left (180°)</option>
              <option value="225">225°</option>
              <option value="270">Back to Front (270°)</option>
              <option value="315">315°</option>
            </select></td>
            <td>Rotates the print in 45° steps</td>
          </tr>
          <tr>
            <td><label for="LINE_NO">Line Numbering:</label></td>
            <td><input name="LINE_NO" type="checkbox" id="LINE_NO" checked="checked" /></td>
            <td>Prints the K-value besides every second test line</td>
          </tr>
          <tr>
            <td colspan="3" class="tdSection"><h4>Advanced:</h4></td>
          </tr>
          <tr>
            <td><label for="NOZ_LIN_R">Nozzle Line Ratio:</label></td>
            <td><input name="NOZ_LIN_R" id="NOZ_LIN_R" step="0.1" value="1.2" onblur="validateInput()" /></td>
            <td>Ratio between extruded line width and nozzle diameter. Should be between 1.05 and 1.2</td>
          </tr>
          <tr>
            <td><label for="OFFSET_Z">Z-Offset:</label></td>
            <td><input name="OFFSET_Z" id="OFFSET_Z" step="any" value="0" onblur="validateInput()" /></td>
            <td>Offset the Z-axis for manual Layer adjustment</td>
          </tr>
          <tr>
            <td><label for="USE_BL">Use Bed Leveling:</label></td>
            <td><select name="SELECT_BED_LEVELING" id="SELECT_BED_LEVELING" onchange="validateInput()">
              <option value="0" selected="selected">No</option>
              <option value="G29 ; Level bed">Level bed (G29)</option>
              <option value="M420 S1 ; Leveling ON">Leveling ON</option>
              <option value="M420 L0 S1 ; Load UBL mesh 0">Load UBL mesh 0</option>
              <option value="M420 L1 S1 ; Load UBL mesh 1">Load UBL mesh 1</option>
              <option value="M420 L2 S1 ; Load UBL mesh 2">Load UBL mesh 2</option>
              <option value="M420 L3 S1 ; Load UBL mesh 3">Load UBL mesh 3</option>
            </select></td>
            <td>Level bed or load a saved mesh (i.e. for UBL) before printing. Bed leveling has to be activated in Configuration.h! Loading a mesh requires UBL to be activated!</td>
          </tr>
          <tr>
            <td><label for="USE_FWR">Use FW Retract</label></td>
            <td><input type="checkbox" name="USE_FWR" id="USE_FWR" /></td>
            <td>Use Firmware Retract. Needs to be activated in Marlin</td>
          </tr>
          <tr>
            <td><label for="EXTRUSION_MULT">Extrusion Multiplier:</label></td>
            <td><input name="EXTRUSION_MULT" id="EXTRUSION_MULT" step="0.1" value="1.0" onblur="validateInput()" /></td>
            <td>Usually 1.0</td>
          </tr>
          <tr>
            <td><label for="PRIME">Prime Nozzle:</label></td>
            <td><input name="PRIME" type="checkbox" id="PRIME" checked="checked" /></td>
            <td>Prime the nozzle before starting the test pattern</td>
          </tr>
          <tr>
            <td><label for="PRIME_EXT">Prime Extrusion Multiplier:</label></td>
            <td><input name="PRIME_EXT" id="PRIME_EXT" step="0.1" value="2.5" onblur="validateInput()" /></td>
            <td>The default of 2.5 results in roughly 1mm of filament for 10mm line length</td>
          </tr>
          <tr>
            <td height="24"><label for="PRIME_SPEED">Prime Printing Speed:</label></td>
            <td><input name="PRIME_SPEED" id="PRIME_SPEED" step="any" value="30" onblur="validateInput()" /></td>
            <td>Speed of the prime move</td>
          </tr>
          <tr>
            <td><label for="DWELL_PRIME">Dwell Time:</label></td>
            <td><input name="DWELL_PRIME" id="DWELL_PRIME" step="0.1" value="2" onblur="validateInput()" /></td>
            <td>Inserts a pause of x seconds before starting the test pattern to bleed off any residual nozzle pressure</td>
          </tr>
          <tr class="calibpat2">
            <td><label for="FILENAME">Filename:</label></td>
            <td colspan="2"><input name="FILENAME" id="FILENAME" value="filename" />
              <input name="button" type="button" id="button" onclick="genGcode()" value="Generate G-code" />
              <input name="button3" type="button" id="button3" onclick="setLocalStorage()" value="Save as default" title="Save settings in a cookie." />
            <p id="warning1" style="display: none;">warning</p>
            <p id="warning2" style="display: none;">warning</p>
            <p id="warning3" style="display: none;">warning</p></td>
            <td><p>
                <input name="button2" type="button" id="button2" onclick="saveTextAsFile()" value="Download as file" />
              </p></td>
          </tr>
        </tbody>
      </table>
      <h3>Notes on the settings:</h3>
      <ul>
        <li><code class="highlighter-rouge">Fast Printing Speed</code> and <code class="highlighter-rouge">Slow Printing Speed</code> should be significantly different or the K-factor effect will barely be visible.</li>
        <li><code class="highlighter-rouge">Use Bed Leveling</code> requires a probe.</li>
        <li>For round beds the option <code class="highlighter-rouge">Origin Bed Center</code> is automatically activated.</li>
        <li>The overall width (X-direction) of the print depends on the <code class="highlighter-rouge">Fast Speed Length</code> and <code class="highlighter-rouge">Slow Speed Length</code> settings plus 5mm for the priming line. The length (Y-direction) depends on the K-factor Settings and <code class="highlighter-rouge">Line Spacing</code>.</li>
        <li>The script checks to make sure the print fits on the bed. Verify it using a host software like <a href="//www.pronterface.com/" target="new">Printrun</a> or <a href="//www.repetier.com/" target="new">Repetier Host</a>.</li>
        <li><code class="highlighter-rouge">Start</code> and <code class="highlighter-rouge">End Value</code> for the K-factor determines the range that the test pattern will cover. For example a <code class="highlighter-rouge">Start Value</code> of 50 and an <code class="highlighter-rouge">End Value</code> of 150 will test a range of 100.</li>
        <li>The <code class="highlighter-rouge">K-factor Stepping</code> determines how many test lines are printed for the above range. For example, a Stepping of 10 and a range of 100 results in 10 test lines. A stepping of 3 would not work in this example as 100 cannot be exactly divided by 3. The script will throw an error message if an exact division is not possible. In this case either the range or the stepping needs to be adjusted.</li>
        <li>The <code class="highlighter-rouge">Alternate Pattern</code> has a second line of <code class="highlighter-rouge">Fast Printing Speed</code> to test 0 to <code class="highlighter-rouge">Fast Printing Speed</code> and back to 0 conditions. Best used with an increased <code class="highlighter-rouge">Test Line Spacing</code> and reduced K-factor range.</li>
        <li>The proper K-factor depends on the filament, nozzle size, nozzle geometry and printing temperature. If any of these values change, the calibration might need to be repeated.</li>
      </ul>
      <h2>Screen-shots</h2>
      <p>The following screen-shots show some examples of the test patterns</p>
      <ul>
        <li>Blue Lines are Slow Printing Speeds</li>
        <li>Red Lines are Fast Printing Speed</li>
        <li>Light blue lines are movements</li>
      </ul>
      <h3>Standard Pattern</h3>
      <p><img src="/assets/images/features/lin_advance/std_pattern.png" alt="StandardPattern" /></p>
      <br />
      <h3>Alternate Pattern with increased Test Line Spacing</h3>
      <p><img src="/assets/images/features/lin_advance/alt_pattern.png" alt="AlternatePattern" /></p>
      <br />
      <h3>Standard Pattern with Frame</h3>
      <p><img src="/assets/images/features/lin_advance/frame_pattern.png" alt="FramePattern" /></p>
      <br />
      <h3>45° rotated Alternate Pattern</h3>
      <p><img src="/assets/images/features/lin_advance/rot_pattern.png" alt="RotatedPattern" /></p>
    </div>
  </div>
</div>
}
